package com.yiwei.controller.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * Hello world!
 *
 */
public class JdbcForSqlServerTest 
{
    public static void main( String[] args )
    {
    	Connection connection = null;
    	Statement statement = null;
    	ResultSet resultSet = null;
    	String connectionString = "jdbc:sqlserver://71.131.222.19:1433;DatabaseName=sqlserver2017_db;"; 
    	try {
    		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
    		connection = DriverManager.getConnection(connectionString, "sa", "qwe20211114.");
    		statement = connection.createStatement();
    		resultSet = statement.executeQuery("select * from PacsApply");
    		int i = 0;
    		while (resultSet.next()) {
    			System.out.println("姓名："+resultSet.getString("Name"));
    		}
    	} catch (Exception e) {
    		e.printStackTrace();
    	} finally {
    		if (connection != null) {
    			try {
    				connection.close();
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    		if (statement != null) {
    			try {
    				statement.close();
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    		if (resultSet != null) {
    			try {
    				resultSet.close();
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    		
    	}

    }
}
